
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
#include<QDialog>
#include<QPainter>
#include<QPixmap>
#include<QTimer>
#include"mypushbutton.h"
#include<QSoundEffect>
#include<QLabel>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->btn_back,&QPushButton::clicked,this,&QWidget::close);
    this->setWindowTitle("koko的小游戏合集");
    this->setWindowIcon(QIcon(":/po/res/ck.png"));
    this->setFixedSize(320,588);
    connect(ui->actionhelp,&QAction::triggered,[=](){
       QMessageBox::information(this,"开始","点击按钮即可开始游戏");

    });
    mypushbutton *btn_str=new mypushbutton(":/po/res/gcoin.png");
    btn_str->setParent(this);
    btn_str->move(this->width()*0.5-btn_str->width()*0.5,this->height()*0.7-100);
    connect(btn_str,&QPushButton::clicked,[=](){
        btn_str->zoom1();
        btn_str->zoom2();
        choose1=new choose;//创建关卡选择的界面
        QTimer::singleShot(150,this,[=](){
            this->hide();
            choose1->show();
            QPushButton * back=new QPushButton("返回",choose1);//创建一个能退回主菜单的按钮
            back->move(230,560);
            back->show();
            connect(back,&QPushButton::clicked,[=](){
            choose1->hide();
            this->show();
                                                });
    });

    });

    mypushbutton *btn_str2=new mypushbutton(":/po/res/g2048.png");
    btn_str2->setParent(this);
    btn_str2->move(this->width()*0.5-btn_str->width()*0.5,this->height()*0.7);
    connect(btn_str2,&QPushButton::clicked,[=](){
        btn_str2->zoom1();
        btn_str2->zoom2();
        game1=new game;//创建关卡选择的界面
        QTimer::singleShot(150,this,[=](){
            this->hide();
            game1->show();
            QPushButton * back=new QPushButton("返回",game1);//创建一个能退回主菜单的按钮
            back->move(230,560);
            back->show();
            connect(back,&QPushButton::clicked,[=](){
                game1->hide();
                this->show();
            });
        });

    });


}

void MainWindow::paintEvent(QPaintEvent *){
    QPainter painter(this);//重载绘图事件
    QPixmap pix;
    pix.load(":/po/res/caodi.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/po/res/Title.png");
    pix=pix.scaled(pix.width()*0.7,pix.height()*0.7);
    painter.drawPixmap(10,30,pix);

}
MainWindow::~MainWindow()
{
    delete ui;
}


